// -*- coding: utf-8 -*- 
/**
 * Project: Java8InActionT
 * Creator: yanking
 * Create time: 2022-02-21 14:55
 * IDE: IntelliJ IDEA
 * Introduction:
 */
package com.ThreadPool.ThreadPoolException;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class ThreadPoolException {
    // 检验线程池异常恢复情况
    public static void main(String[] args) throws InterruptedException {
        ExecutorService es1 = Executors.newFixedThreadPool(1);
        ExecutorService es2 = Executors.newSingleThreadExecutor();
        testException(es1);
        TimeUnit.SECONDS.sleep(12);
        testException(es2);

    }

    // 异常恢复检验方法
    public static void testException(ExecutorService es) {
        es.submit(() -> {
            throw new IllegalStateException("Error!");
        });
        es.submit(() -> {
            System.out.println("running......");
        });

    }


}
